from time import time

def add_str(cls):
    '''
    这个装饰器主要用于装饰 类，给类添加 __str__ 方法 
    '''
    def __str__(self):
        return str(self.__dict__)
    cls.__str__ = __str__
    return cls

if __name__ == '__main__':
    class Test_add_str():
        @add_str
        class MyObject():
            def __init__(self, a, b):
                self._a = a 
                self._b = b
        o = MyObject(1,2)
        print(o)

class Decorator():
    def exe_time(origin):
        def inner(*args, **kwargs):
            print(args,kwargs)
            start = time()
            result = origin(*args, **kwargs)
            print(time() - start)
            return result
        return inner

    def exe_times(n):
        def outter(origin):
            def inner(*args, **kwargs):
                for _ in range(0, n):
                    result = origin(*args, **kwargs)
                return result
            return inner
        return outter

if __name__ == '__main__':
    @Decorator.exe_time
    @Decorator.exe_times(1)
    def test():
        print('test')
    test()
